package cn.tedu.hhmc.sign.service.impl;

import java.util.List;

import cn.tedu.hhmc.patient.mapper.PatientMapper;
import cn.tedu.hhmc.patient.pojo.vo.PatientVO;
import cn.tedu.hhmc.sign.mapper.SignedContractInfoMapper;
import cn.tedu.hhmc.sign.pojo.dto.SignedContractInfoDTO;
import cn.tedu.hhmc.sign.pojo.dto.SignedContractInfoParam;
import cn.tedu.hhmc.sign.pojo.entity.SignedContractInfo;
import cn.tedu.hhmc.sign.pojo.vo.SignedContractInfoVO;
import cn.tedu.hhmc.sign.service.ISignedContractInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 待处理服务项目信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-05
 */
@Slf4j
@Service
public class SignedContractInfoServiceImpl implements ISignedContractInfoService
{
    @Autowired
    private SignedContractInfoMapper signedContractInfoMapper;
    @Autowired
    private PatientMapper patientMapper;

    /**
     * 查询待处理服务项目信息
     * 
     * @param id 待处理服务项目信息主键
     * @return 待处理服务项目信息
     */
    @Override
    public SignedContractInfoVO selectSignedContractInfoById(Long id)
    {
        SignedContractInfoVO signedContractInfoVO = signedContractInfoMapper.selectSignedContractInfoById(id);
        PatientVO patientVO = patientMapper.selectPatientById(id);
        signedContractInfoVO.setName(patientVO.getName());
        signedContractInfoVO.setIdcard(patientVO.getIdCardNumber());
        signedContractInfoVO.setPhone(patientVO.getPhoneNumber());
        signedContractInfoVO.setGender(patientVO.getGender());
        signedContractInfoVO.setBirthDate(patientVO.getBirthDate());
        signedContractInfoVO.setAge(patientVO.getAge());
        signedContractInfoVO.setAddress(patientVO.getAddress());
        return signedContractInfoVO;
    }

    /**
     * 查询待处理服务项目信息列表
     * 
     * @param SignedContractInfoDTO 待处理服务项目信息
     * @return 待处理服务项目信息
     */
    @Override
    public List<SignedContractInfoVO> selectSignedContractInfoList(SignedContractInfoDTO signedContractInfoDTO)
    {
        log.debug("查询待处理签约列表业务,参数:{}",signedContractInfoDTO);
        List<SignedContractInfoVO> list = signedContractInfoMapper.selectSignedContractInfoList(signedContractInfoDTO);
        for (SignedContractInfoVO signedContractInfoVO : list) {
            Long id = signedContractInfoVO.getPatientId();
            PatientVO patientVO = patientMapper.selectPatientById(id);
            signedContractInfoVO.setName(patientVO.getName());
            signedContractInfoVO.setIdcard(patientVO.getIdCardNumber());
            signedContractInfoVO.setPhone(patientVO.getPhoneNumber());
            signedContractInfoVO.setGender(patientVO.getGender());
            signedContractInfoVO.setBirthDate(patientVO.getBirthDate());
            signedContractInfoVO.setAge(patientVO.getAge());
            signedContractInfoVO.setAddress(patientVO.getAddress());
        }
        return list;
    }

    /**
     * 新增待处理服务项目信息
     * 
     * @param signedContractInfo 待处理服务项目信息
     * @return 结果
     */
    @Override
    public int insertSignedContractInfo(SignedContractInfo signedContractInfo)
    {
        return signedContractInfoMapper.insertSignedContractInfo(signedContractInfo);
    }

    /**
     * 修改待处理服务项目信息
     * 
     * @param signedContractInfo 待处理服务项目信息
     * @return 结果
     */
    @Override
    public int updateSignedContractInfo(SignedContractInfoParam signedContractInfoParam)
    {
        log.debug("更新签约列表的状态业务,参数:{}",signedContractInfoParam);
        SignedContractInfo signedContractInfo = new SignedContractInfo();
        BeanUtils.copyProperties(signedContractInfoParam,signedContractInfo);
        return signedContractInfoMapper.updateSignedContractInfo(signedContractInfo);
    }

    /**
     * 批量删除待处理服务项目信息
     * 
     * @param ids 需要删除的待处理服务项目信息主键
     * @return 结果
     */
    @Override
    public int deleteSignedContractInfoByIds(Long[] ids)
    {
        return signedContractInfoMapper.deleteSignedContractInfoByIds(ids);
    }

    /**
     * 删除待处理服务项目信息信息
     * 
     * @param id 待处理服务项目信息主键
     * @return 结果
     */
    @Override
    public int deleteSignedContractInfoById(Long id)
    {
        return signedContractInfoMapper.deleteSignedContractInfoById(id);
    }
}
